package org.xzx.shop_api.utils;

import lombok.Data;
import org.springframework.data.domain.Sort;

@Data
public class JsonResult {
    private int code;
    private String message;
    private Object data;
    public JsonResult(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    //成功的响应
    public static JsonResult success(String message, Object data) {
        return new JsonResult(200, message, data);
    }

    //失败的响应
    public static JsonResult failed(String message) {
        return new JsonResult(500, message,null);
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
